package org.example.controller;

import lombok.RequiredArgsConstructor;
import org.example.domain.ResponseResult;
import org.example.domain.dto.CityListDto;
import org.example.domain.entity.City;
import org.example.enums.AppHttpCodeEnum;
import org.example.exception.SystemException;
import org.example.service.CityService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/city")
@RequiredArgsConstructor
public class CityController {

    private final CityService cityService;


    @PostMapping("/addCity")
    public ResponseResult addCity(@RequestBody City city){
        String cityName = city.getCityName();
        if(!StringUtils.hasText(cityName)){
            throw new SystemException(AppHttpCodeEnum.NOT_CITY_NAME_ERROR);
        }
        return cityService.addCity(city);
    }

    @PostMapping("/cityList")
    public ResponseResult cityList(@RequestBody CityListDto cityListDto){

        return cityService.cityList(cityListDto);
    }

    @GetMapping("/selectAllCity")
    public ResponseResult selectAllCity(){

        return cityService.selectAllCity();

    }

    @PutMapping("/updateCity")
    public ResponseResult updateCity(@RequestBody City city){

        return cityService.updateCity(city);

    }

}
